package com.uchedao.vehicledetection.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.uchedao.vehicledetection.R;
import com.uchedao.vehicledetection.adapter.CityListAdapter;
import com.uchedao.vehicledetection.model.Address;
import com.uchedao.vehicledetection.utils.city.CityUtil;
import com.uchedao.vehicledetection.view.baseinfo.BaseInfoCarInfoView;


public class CityListActivity extends CJDBaseActivity {

    private ListView lvCity;

    private Address address;

    @Override
    protected String getActivityTag() {
        return "CityListActivity";
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_city_list;
    }

    @Override
    protected void initView() {
        lvCity = (ListView) findViewById(R.id.lvCity);
    }

    @Override
    protected void initData() {
        setTitle("城市选择");
        address = (Address) getIntent().getSerializableExtra(BaseInfoCarInfoView.KEY_DATA);
        lvCity.setAdapter(new CityListAdapter(this, CityUtil.getInstance(this).getCityData(address.getProvince())));
    }

    @Override
    protected void initListener() {
        findViewById(R.id.title_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        lvCity.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                String city = (String) adapterView.getItemAtPosition(i);
                Intent data = new Intent();
                //id?
                address.setCity(city);
                data.putExtra(BaseInfoCarInfoView.KEY_DATA, address);
                setResult(RESULT_OK, data);
                finish();
            }
        });
    }
}
